package com.wmyg.antifake.utils;

import java.security.cert.CertificateFactory;
import java.util.Random;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-10
 */
public class TsStringCreator {

    private static final String SOURCE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String randomString(int length) {
        StringBuffer sb = new StringBuffer();
        for (int i=0; i<length; i++) {
            Random random = new Random();
            sb.append(SOURCE.charAt(random.nextInt(SOURCE.length())));
        }
        return sb.toString();
    }

    public static String parseInt(Integer in, int length) {
        StringBuffer sb = new StringBuffer();
        for (int i=0; i<length; i++) {
            sb.append(SOURCE.charAt(in%SOURCE.length()));
            in = in/SOURCE.length();
        }
        return sb.reverse().toString();
    }

    public static Integer parseString(String in, int length) {
        Integer result = 0;
        for (int i=0; i<length; i++) {
            result = result * 36 + SOURCE.indexOf(in.charAt(i));
        }
        return result;
    }

    public static void main(String[] args) {
//        System.out.println(parseString("00000", 5));
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
